<?php
/**
 * Created by PhpStorm.
 * User: david
 * Date: 3/22/19
 * Time: 8:30 PM
 */

namespace App\Transformers;


use App\Models\Project;
use League\Fractal\TransformerAbstract;

class ProjectTransformer extends TransformerAbstract
{
    protected $defaultIncludes = ['department'];

    public function transform(Project $project)
    {
        return [
            'id' => $project->id,
            'name' => $project->name,
            'department_id' => $project->department_id,
            'post' => $project->post,
            'principal' => $project->principal,
            'people' => $project->people,
            'status' => Project::STATUS_NAME[(int) $project->status],
            'start_time' => $project->start_time,
            'start_time_format' => date('Y-m-d', $project->start_time),
            'end_time' => $project->end_time,
            'end_time_format' => date('Y-m-d', $project->end_time),
            'created_at' => $project->created_at ? $project->created_at->toDateTimeString() : null,
            'updated_at' => $project->updated_at ? $project->updated_at->toDateTimeString() : null,
        ];
    }

    public function includeDepartment(Project $project)
    {
        return $this->item($project->department, new DepartmentTransformer());
    }
}